package comoabejas

import com.grailsrocks.authentication.AuthenticatedUser;
import com.grailsrocks.authentication.AuthenticationUser
import org.springframework.web.context.support.WebApplicationContextUtils

import comoabejas.EmailService

//http://localhost:8080/ComoAbejas/email?to=matiaskochman@yahoo.com.ar&subject=hello+world&body=This+is+a+test
class EmailController {
    EmailService emailService
	
	def appCtx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext)
	
    // Send an email
    def index = {
        // Each "email" is a simple Map
        def email = [
            to: [ params.to ],        // "to" expects a List, NOT a single email address
            subject: params.subject,
            text: params.body         // "text" is the email body
        ]
        // sendEmails expects a List
		try{
			emailService.sendEmails([email])
		}catch(org.springframework.mail.MailSendException e){
			e.printStackTrace();
		}
        render("done")
    }
	
	def emailUserConfirmation = {
		String password = params.password
		
		User user = emailService.emailUserConfirmation(password)
		 
        render(view: "usuarioCreado", model: [user: user])
	}

}
